package com.website;

import com.website.config.properties.WebsiteProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * SpringBoot方式启动类
 *
 * @author yanqb
 * @Date 2018-11-17 12:06
 */
@SpringBootApplication
public class WebsiteApplication extends WebMvcConfigurerAdapter{

    protected final static Logger logger = LoggerFactory.getLogger(WebsiteApplication.class);

    @Autowired
    WebsiteProperties websiteProperties;

    /**
     * 增加swagger的支持
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 添加外部资源，线上便于维护（每次打包有可能丢失文件）前面是访问路径，后面是映射路径
        registry.addResourceHandler("/files/**").addResourceLocations("file:D:/0000_git_work/files/");
       // registry.addResourceHandler("/files/**").addResourceLocations("file:/files/");
        if(websiteProperties.getSwaggerOpen()){
            registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
            registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        }
        super.addResourceHandlers(registry);
    }

    public static void main(String[] args) {
        SpringApplication.run(WebsiteApplication.class, args);
        logger.info("GunsApplication is success!");
    }
}
